﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace RTGS.Library.Report
{
   public class ReportSptDetailRecordI
    {

        private string errorLog;
        private string connectionString;

        public ReportSptDetailRecordI(string ConnectionString)
        {
            errorLog = string.Empty;
            connectionString = ConnectionString;
        }

        public DataTable GetReportIncoming(string status)
        {
            DataTable dt = new DataTable();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"

 SELECT 
ROW_NUMBER()OVER(ORDER BY RECORD_DETAIL_ITR_RelatedTRN DESC) Row
,LTRIM(RTRIM(RECORD_DETAIL_ITR_FromMember)) RECORD_DETAIL_ITR_FromMember
,LTRIM(RTRIM(RECORD_DETAIL_ITR_TRN)) RECORD_DETAIL_ITR_TRN
,LTRIM(RTRIM(RECORD_DETAIL_ITR_RelatedTRN)) AS RelatedTRN
,LTRIM(RTRIM(RECORD_DETAIL_IST_UltimateBenefName)) AS RECORD_DETAIL_IST_UltimateBenefName
,ISNULL(LTRIM(RTRIM(RECORD_DETAIL_IST_Status)),'') AS Status
,LTRIM(RTRIM(RECORD_DETAIL_ITR_Amount))  AS RECORD_DETAIL_ITR_Amount
,LTRIM(RTRIM(RECORD_DETAIL_IRECORD_IH_BatchReference)) AS RECORD_DETAIL_IRECORD_IH_BatchReference
,LTRIM(RTRIM(RECORD_DETAIL_IST_UltimateBenefAccount)) AS RECORD_DETAIL_IST_UltimateBenefAccount
FROM STP_RECORD_DETAIL_I
WHERE RECORD_DETAIL_IST_Status='" + status+"'";

                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;

                    try
                    {
                        conn.Open();
                        da.Fill(dt);
                    }
                    catch (Exception ex)
                    {
                        errorLog = ex.Message;
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }

                }
            }

            return dt;

        }
    }
}

